package net.ruixin.session;

import org.apache.shiro.authc.*;
import org.apache.shiro.realm.AuthenticatingRealm;

/**
 * 身份认证域实现
 * @author mxding
 * @date 2021-04-23 15:46
 */
public class ShiroRealm extends AuthenticatingRealm {

    @Override
    public boolean supports(AuthenticationToken token) {
        return token instanceof UsernamePasswordToken;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        Object principal = token.getPrincipal();
        if(!"admin".equals(principal)) {
            throw new UnknownAccountException();
        }
        return new SimpleAuthenticationInfo("admin", "111", getName());
    }
}
